    <!DOCTYPE html>
<html>
	<head>
		<title>设置个人资料</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/myInfo.css" />
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<script src="/js/plugins/form/jquery.form.js"></script>
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">

		
	</head>

	<body>

		<div class="search-head">
			<div class="row nav-search">
				<div class="col">
					<a href="javascript:window.history.go(-1);">
						<span>取消</span>
					</a>
				</div>
				<div class="col">
					<span>设置个人资料</span>
				</div>
				<div class="col" >
					<a role="button" id="saveBtn" >
						<span>保存</span>
					</a>
				</div>
			</div>
		</div>

		<div class="container info">
			<div class="myBg">
				<img id="headImg"  class="rounded-circle" render-src="headImgUrl"/>
				<div class="editHead" id="headBtn" >
					<i class="fa fa-pencil-square fa-lg"  aria-hidden="true"></i></div>
				<button  class="btn btn-outline-light ibtn " id="coverBtn">设置背景</button>
				<form action="/images" method="post" id="imagesForm" enctype="multipart/form-data">
					<input type="file" name="file"/>
				</form>
			</div>

			<form id="infoForm" method="post">
					<input type="hidden" name="headImgUrl" render-value="headImgUrl"/>
					<input type="hidden" name="coverImgUrl" render-value="coverImgUrl" />
					<input type="hidden" name="_method" value="put" />

					<label>昵称</label><input type="text" name="nickName" class="form-control" render-value="nickName">
					<label>性别</label><select class="form-control" name="gender" render-value="gender">
							<option value="-1">保密</option>
							<option value="1">男</option>
							<option value="0">女</option>
						</select>
					<label>地区</label><input  type="text" name="place"  class="form-control" render-value="place">
					<label>签名</label><textarea name="sign" render-value="sign" class="form-control" rows="5" ></textarea>
			</form>
		</div>
		
		
		<script>
			var user = JSON.parse(sessionStorage.getItem("user"));
			var flag = null;
			$(".info").renderValues(user);
			//背景图片回显
			$(".myBg").css("background-image","url('"+user.coverImgUrl+"')");
			//设置隐藏的文件提交表单控件
			$("input[name='file']").css("display","none");
			//头像编辑点击事件
            $("#headBtn").click(function () {
                $("input[name='file']").click();
                flag = true;
            });
            $("#coverBtn").click(function () {
                $("input[name='file']").click();
                flag = false;
            });

            //值改变事件
            $("input[name='file']").change(function () {
				$("#imagesForm").ajaxSubmit(function (data) {
                    if (data.status == 1) {
                        if (flag) {
                        	$("#headImg").attr("src",data.url);
                            $("input[name='headImgUrl']").val(data.url);
                        }else{
                            $(".myBg").css("background-image","url('"+data.url+"')");
                            $("input[name='coverImgUrl']").val(data.url);
                        }
                    }else if(data.status == 0){
                        $(document).dialog({
                            type : 'confirm',
                            closeBtnShow: true,
                            content: data.msg
                        });
					}
                });
            });
            //提交表单
            $("#infoForm").attr("action","/users/" + user.id);
			$("#saveBtn").click(function () {
				$("#infoForm").ajaxSubmit(function (data) {
                    sessionStorage.setItem("user",JSON.stringify(data.result));
                    window.parent.location.href = "/mine/profiles.html";
                });
            });

		</script>
	</body>
</html>
